package com.sinosoft.online.webservice.dto;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.sinosoft.online.webservice.constant.WebServiceConstants;

/**
 * WebService服务请求、响应对象头部属性
 * @author xiaoxiong
 *
 */
public class Header {
	
	private String sender;	//	发送应用
		
	private String receiver;	//	接收应用
	
	private String sendTime;	//	发送时间
	
	private String msgType;	//	消息类型
	
	private String msgID;	//	消息编号

	public Header() {}
	
	
	/**
	 * 单个接收方消息头构造器
	 * @param receiver	接收方
	 * @param msgType	消息类型
	 */
	public Header(String msgType, String receiver) {
		this.sender = WebServiceConstants.SYS_PLAT_ID;
		this.receiver = receiver;
		this.msgType = msgType;
		this.sendTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	}
	
	/**
	 * 多个接收方消息头构造器
	 * @param msgType	消息类型
	 * @param receiver	接收方
	 */
	public Header(String msgType, String... receiver) {
		this.sender = WebServiceConstants.SYS_PLAT_ID;
		String receivers = "";
		if(receiver != null) {
			for(int i=0; i<receiver.length; i++) {
				if(i == 0) {
					receivers=receivers.concat(receiver[i]);
				} else {
					receivers=receivers.concat("," + receiver[i]);
				}
			}
		}
		this.receiver = receivers;
		this.sendTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		this.msgType = msgType;
		this.msgID = this.sender+this.sendTime;
		
	}
	
	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	public String getSendTime() {
		return sendTime;
	}

	public void setSendTime(String sendTime) {
		this.sendTime = sendTime;
	}

	public String getMsgType() {
		return msgType;
	}

	public void setMsgType(String msgType) {
		this.msgType = msgType;
	}

	public String getMsgID() {
		return msgID;
	}

	public void setMsgID(String msgID) {
		this.msgID = msgID;
	}
	
}
